package com.moli.iov.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moli.iov.sys.mapper.ClientDetailsMapper;
import com.moli.iov.sys.model.dto.req.ClientDetailsReqDto;
import com.moli.iov.sys.model.po.ClientDetails;
import com.moli.iov.sys.service.IClientDetailsService;
import com.moli.iov.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 企业客户端信息 服务实现类
 * </p>
 *
 * @author zql
 * @since 2019-09-04I
 */
@Service
public class ClientDetailsServiceImpl extends ServiceImpl<ClientDetailsMapper, ClientDetails> implements IClientDetailsService {

  @Autowired
  private ClientDetailsMapper clientDetailsMapper;

  /**
   * 添加 企业客户端信息
   * @param clientDetails
   * @return
   */
  @Override
  public int saveClientDetails(ClientDetails clientDetails) {
    return clientDetailsMapper.insert(clientDetails);
  }

  /**
   * 获取客户端信息
   * @param clientDetailsReqDto
   * @return
   */
  @Override
  public ClientDetails getClientDetails(ClientDetailsReqDto clientDetailsReqDto) {
    return super.getOne(assemblyConditions(clientDetailsReqDto), false);
  }

  /**
   * 组装查询条件
   * @param clientDetailsReqDto
   * @return
   */
  private QueryWrapper<ClientDetails> assemblyConditions(ClientDetailsReqDto clientDetailsReqDto){
    QueryWrapper<ClientDetails> queryWrapper = new QueryWrapper<>();

    if(clientDetailsReqDto == null){
      return queryWrapper;
    }

    if(StringUtil.isNotBlank(clientDetailsReqDto.getAppId())){
      queryWrapper.eq("app_id", clientDetailsReqDto.getAppId());
    }

    if(clientDetailsReqDto.getCompanyId() != null){
      queryWrapper.eq("company_id", clientDetailsReqDto.getCompanyId());
    }

    return queryWrapper;
  }


}
